import pandas as pd
from .base import ContentExtractor, FileReadError
from typing import List


class ExcelExtractor(ContentExtractor):
    """Excel文件提取器"""

    def extract(self, file_path: str) -> str:
        try:
            xls = pd.ExcelFile(file_path)
            content = []

            for sheet_name in xls.sheet_names:
                df = pd.read_excel(xls, sheet_name=sheet_name)
                content.append(f"=== Sheet: {sheet_name} ===")
                content.append(df.to_string(index=False))
                content.append("\n")  # 添加分隔空行

            return '\n'.join(content)
        except Exception as e:
            raise FileReadError(file_path, str(e))